package com.ivan.common.exception;

import com.ivan.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Ivan
 * @date 2021/3/13 22:51
 * @Description: 全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)//处理Exception异常
    @ResponseBody//返回json数据
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(IvanException.class)//处理IvanException异常
    @ResponseBody//返回json数据
    public Result error(IvanException e) {
        e.printStackTrace();
        return Result.fail();
    }
}
